﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;

namespace YouHP.Pages
{
    public class ListDiseases : BasePage
    {
        protected static List<string> mPingYin = new List<string>();

        static ListDiseases()
        {
            for (char c = 'A'; c <= 'Z'; c++)
            {
                mPingYin.Add(c.ToString());
            }
        }

        protected List<DiseaseInfo> mDiseaseLst;
        protected List<DiseaseTypeInfo> mDiseaseTypeLst;
        protected int _pageCount = 0;
        protected int _DiseaseCount = 0;
        protected int _pageSize = 2;
        protected int _pageIndex = 1;
        protected int _firstpage = 1;
        protected int _prevpage;
        protected int _nextpage;
        protected int PatientCount = 50;
        protected string url = "ListDiseases.aspx?";
        protected string CssUrl = "/support/Css/mycss";

        protected override void ShowPage()
        {
            //SeoTitle = "列表";
            PageTitle = "疾病";
            AddLinkCss(CssUrl);

            mDiseaseTypeLst = DiseaseBLL.Instance.GetDiseaseTypeList();

            //当前页
            _pageIndex = RequestTools.GetQueryInt("page", 1);

            //页面跳转
            int pagesel = RequestTools.GetFormInt("pagesel", 0);
            if (pagesel != 0) _pageIndex = pagesel;

            mDiseaseLst = DiseaseList();

            //分页计算
            _pageCount = _DiseaseCount / _pageSize;

            if (_DiseaseCount / _pageSize == 0) _pageCount++;

            else if (_DiseaseCount % _pageSize != 0) _pageCount++;

            //前后翻页计算
            _prevpage = _pageIndex - 1;
            if (_prevpage == 0) _prevpage++;

            _nextpage = _pageIndex + 1;
            if (_nextpage > _pageCount) _nextpage = _pageCount;
        }


        public List<DiseaseInfo> DiseaseList()
        {
            //搜索治疗
            string tname1 = RequestTools.GetQueryString("Diseasename");
            if (tname1 != "")
            {
                mDiseaseLst = DiseaseBLL.Instance.GetDiseaseByName(_pageSize, _pageIndex, tname1, out _DiseaseCount);
                url = url + "Diseasename=" + tname1;
                if (mDiseaseLst.Count == 0)
                    this.AddErrLine("请输入正确的疾病名称");
                return mDiseaseLst;
            }

            //拼音首字母排列
            string pinyin = RequestTools.GetQueryString("PinYin");
            if (!pinyin.Equals(""))
            {

                url = url + "PinYin=" + pinyin;
                mDiseaseLst = DiseaseBLL.Instance.GetDiseaseByPinYin(_pageSize, _pageIndex, pinyin, out _DiseaseCount);
                return mDiseaseLst;
            }
            
            //治疗类型排序
            int DiseaseType = RequestTools.GetQueryInt("DiseaseTypeId", -1);
            if (DiseaseType != -1)
            {
                url = url + "DiseaseTypeId=" + DiseaseType;
                mDiseaseLst = DiseaseBLL.Instance.GetDiseaseByType(_pageSize, _pageIndex, DiseaseType, out _DiseaseCount);
                return mDiseaseLst;
            }
            else
            {
                mDiseaseLst = DiseaseBLL.Instance.GetDiseaseList(_pageSize, _pageIndex, out _DiseaseCount);
                return mDiseaseLst;
            }
        }
    }
}
